<?php
/**
*@作者:MissZhang
*@邮箱:<787727147@qq.com>
*@创建时间:2021/8/12 上午9:24
*@说明:地区模型
*/
namespace app\common\model;
use think\Model;

class Region extends Model
{
    protected $pk = "id";
    // 关闭时间戳自动写入
    protected $autoWriteTimestamp = false;
    public function getPkAttr() {
        return $this->pk;
    }
    public function getParentTextAttr($value,$data) {
        if ($data['parent_id']>0){
            $parent_id=$data['parent_id'];
            $level=$this->where('id',$parent_id)->value('level');
            if ($level==1){
                $text=$this->where('id',$parent_id)->value('name');
            }else{
                $find=$this->where('id',$parent_id)->find();
                $parent_name=$this->where('id',$find['parent_id'])->value('name');
                $text="{$parent_name}>{$find['name']}";
            }
            return $text;
        }
        return 0;
    }
}